package com.belf.evaluatetool.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import java.io.File;

@RestController//将类声明为控制器
public class HelloController {
    @RequestMapping("/hello")//处理 "/hello" 路径的请求
    public String hello() {
        System.out.println("hello world");//它打印"hello world"到控制台
        String projectPath = System.getProperty("user.dir");
        File projectDir = new File(projectPath + "/evalTool.zip");
        System.out.println("projectPath: " + projectDir);
        return projectDir.getPath();//返回字符串"Hello World"作为HTTP响应内容
    }

    // 也可以使用@GetMapping注解单独指定GET请求的首页路径
    @GetMapping("/")
    public ModelAndView anotherHomePage() {
        // 创建RedirectView对象并设置要重定向到的端点
        RedirectView redirectView = new RedirectView("/home.html");
        return new ModelAndView(redirectView);
    }

}